About 757 letters

About 4 minutes

#sorted

Description: Sort.

def sorted(iterable, /, *, key=None, reverse=False):
    '''
    Sort the iterable

    :param iterable: An iterable object
    :param key: A callback function that returns the comparison key
    :param reverse: Whether to sort in reverse order
    :return: The sorted iterable
    '''

Example:

numbers:list[int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(sorted(numbers))
print(sorted(numbers, reverse=True))

pets = [('Tom', 8), ('Jerry', 9), ('Spike', 5), ('Tuffy', 3)]
print(sorted(pets))
print(sorted(pets, key=lambda x:x[1]))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Updated: 6/9/2025

Author: PlanC

Created: 6/9/2025